// pages/order/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loading: 0,
    page: 1,
    user_info:{
      commission_nums:{
        
      }
    },
    status: 1,
    lastpage: 0,
    listData: [],
    nodata: 0,
  },

  getUserInfo() {
    var that = this;
    app.api("api/user/info", { "fields":"roleId,user_id,nickname,commission_nums,partner_user_id"}, function (res) {
      if (res.code != 200) {
        app.alert(res.msg);
        return;
      }
    
      that.setData({
        user_info: res.data
      });

    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({ extConfig: app.getExtConfigSync() })
    if (options.status) {
      this.data.status = options.status;
      this.setData({ status: options.status });
    }
    app.getUserInfo((user_info)=>{
      this.getUserInfo();
    });
    this.loadOderList();
  },
  setUserFee:function(e){
    if (this.data.status!=1){
      return;
    }
    if (this.data.user_info && this.data.user_info.commission_nums && this.data.user_info.commission_nums.shop<0.38){
      var user_id = e.currentTarget.dataset.user_id;
      wx.navigateTo({
        url: '/pages/partner/setUserFee?user_id=' + user_id,
      })
    }
   
  },
  setStatus: function (e) {
    var status = e.currentTarget.dataset.status;
    if (this.data.status == status) {
      return;
    }
    this.setData({ status: status });
    this.loadOderList(1);
    //console.log(e);
  },
  
  loadOderList: function (reload) {
    var that = this;

    if (reload == 1) {
      this.setData({
        loading: 0,
        page: 1,
        lastpage: 0,
        listData: [],
      });
    }

    var page = this.data.page;
    if (this.data.loading == 1 || this.data.lastpage == 1) {
      //console.log(this.data);
      return;
    }
    this.data.loading = 1;
    app.api("apiv2/user/get", {
      page: page,
      limit: 10,
      status: this.data.status,
      order: 'user_id desc'
    }, function (res) {
      that.data.loading = 0;
      if (res.code != 200) {
        app.alert(res.msg);
        return;
      }
      var nodata = 0;
      if (res.data.list.length == 0) {
        that.data.lastpage = 1;
      }
      var list = that.data.listData.concat(res.data.list);
      if (list.length == 0) {
        nodata = 1;
      }
      that.data.page++;
      that.setData({
        listData: list,
        nodata: nodata
      });
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getUserInfo();
    this.loadOderList(1);
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.loadOderList();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})